var vm=new Vue({
	el: '#login',
	data: {
		user: {}
	},
	methods: {
		presentBtn: function(url) {
			if(!this.user.optNo){
				showAlert("用户名不能为空");
				return;
			}
			if(!this.user.password){
				showAlert("密码不能为空");
				return;
			}
			if(!this.user.validateCode){
				showAlert("验证码不能为空");
				return;
			}
			
			App.ajax({
    			type:"POST",
    			url:App.getApiUrl("loginUser"),
    			data:this.user,
    			success:function(data){
    				window.location.href=App.getBaseUrl() + "main/index.html";
				},
				error:function(){
					vm.changeBtn();
				}
			});
		},
		changeBtn:function(){
			$("#loginImg").attr("src", App.getApiUrl("getUserCode") + "?"+Math.random())
		}
	},
	created: function () {
		this.changeBtn();
	}
})


//显示警告框
function showAlert(text,callback){
	if(text){
		$("#my-alert").find(".am-modal-bd").html(text);
	}
	var $confirm = $('#my-alert');
	var $confirmBtn = $confirm.find('[data-am-modal-confirm]');
	$confirmBtn.off('click.confirm.modal.amui').unbind("click"); //移除click
	$confirmBtn.off('click.confirm.modal.amui').on('click', function() {
		if(callback){
        	callback();
        }
	});

	
	$('#my-alert').modal({
        relatedTarget: this,
    });
}